package com.tgu.home_action.dao;

import com.tgu.home_action.pojo.Volunteer;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface VolunteerMapper {
    /**
     * 通过openid查询志愿者用户
     *
     * @param openid：openid
     * @return volunteer
     */
    @Select("select * from volunteer_users where openid=#{openid}")
    Volunteer getByOpenid(String openid);

    /**
     * 插入志愿者用户
     *
     * @param volunteer：志愿者用户
     */
    void insertVolunteer(Volunteer volunteer);

    /**
     * 通过id查询志愿者用户
     *
     * @param id：志愿者id
     * @return volunteer
     */
    @Select("select * from volunteer_users where id=#{id}")
    Volunteer getById(Integer id);

    /**
     * 更新从微信获取的头像和昵称信息
     *
     * @param volunteer：信息
     */
    void updateUserinfo(Volunteer volunteer);

    /**
     * 绑定/更改手机号
     */
    @Update("update volunteer_users set phone=#{phone} where id=#{id}")
    void updatePhone(Volunteer volunteer);

    /**
     * 通过id获取openid
     */
    @Select("select openid from volunteer_users where id=#{id}")
    String getOpenidById(Integer id);

    /**
     * 通过Id获取手机号
     */
    @Select("select phone from volunteer_users where id=#{id}")
    String getPhoneById(Integer id);

    /**
     * 通过informationId查询志愿者用户
     */
    Volunteer getByInformationId(Integer informationId);

    /**
     * 修改手机号和state
     */
    void updatePhoneAndState(Volunteer volunteer);

    /**
     * 删除志愿者用户
     */
    @Delete("delete from volunteer_users where id=#{volunteerId}")
    void delVolunteer(Integer volunteerId);
}
